<template>
	<view class="container">
		<!-- 未登录 -->
		<view class="empty-container" v-if="!userInfo.signature">
			<img src="/static/waiter.svg" alt="空状态">
			<view class="title">您还没有登录，请登录后查看</view>
			<view class="login" @click="toLogin">登录</view>
		</view>
		<!-- 登录后 -->
		<view class="list-c" v-else>
			<view class="item" v-for="(item, index) in digestlist" :key="index">
				<view class="shop-info">
					<img :src="item.poi_pic">
					<span class="shop-name">{{item.poi_name}}</span>
					<i class="icon mt-arrow-right-o"></i>
					<span class="order-status">{{item.status_description}}</span>
				</view>
				<view class="googs-c">
					<view class="goods" v-for="(itx, idx) in item.product_list" :key="idx">
						<span class="s-l">{{itx.product_name}}</span>
						<span class="s-r">x{{itx.product_count}}</span>
					</view>
				</view>
				<view class="price">
					<span class="count">共{{item.product_list.length}}件商品，实付</span>
					<span class="amount">￥{{item.total}}</span>
				</view>
				<view class="bottom-c">
					<view class="btn">
						<span>再来一单</span>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {mapActions, mapGetters, mapState} from 'vuex'
	export default {
		data() {
			return {
				userInfo: {}, // 用户信息
			}
		},
		computed: {
			...mapState({
				orderInfo: state => state.orderInfo.orderInfo
			}),
			...mapGetters(['digestlist'])
		},
		methods: {
			...mapActions(['getOrderInfo']),
			// 跳转到登录页面
			toLogin() {
				if (!this.userInfo.signature) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			},
			// 获取用户信息
			getUserInfo() {
				// 尝试读取用户信息
				const userInfo = uni.getStorageSync('userInfo')
				// 判断是否已登录
				if (userInfo) {
					this.userInfo = JSON.parse(userInfo)
				}
			}
		},
		onShow() {
			const userInfo = uni.getStorageSync('userInfo')
			if (!userInfo) {
				this.userInfo = {}
			}
		},
		mounted() {
			this.getUserInfo()
			this.getOrderInfo()
		}
	}
</script>

<style lang="scss" scoped>
.container {
	// 未登录
	.empty-container {
		display: flex;
		flex-direction: column;
		align-items: center;
		img {
			width: 180upx;
		}
		.title {
			font-size: 28upx;
		}
		.login {
			width: 140upx;
			height: 80upx;
			line-height: 80upx;
			font-size: 28upx;
			text-align: center;
			border-radius: 10upx;
			background-color: $theme-color;
			margin-top: 30upx;
		}
	}
	// 登录订单列表样式
	.list-c {
		display: flex;
		flex-direction: column;
		.item {
			display: flex;
			flex-direction: column;
			background-color: white;
			margin-top: 20rpx;
			.shop-info {
				display: flex;
				height: 120rpx;
				background-color: white;
				align-items: center;
				border-bottom: 2rpx solid $spLine-color;
				margin-left: 30rpx;
				margin-bottom: 10rpx;
				img {
					width: 80rpx;
					height: 60rpx;
				}
				.shop-name {
					font-size: 32rpx;
					color: $textBlack-color;
					margin-left: 10rpx;
					font-weight: bold;
				}
				i {
					font-size: 28rpx;
					color: $textGray-color;
					margin-left: 10rpx;
					flex: 1;
				}
				.order-status {
					font-size: 28rpx;
					color: $textDarkGray-color;
					display: flex;
					margin-right: 20rpx;
				}
			}
			.googs-c {
				display: flex;
				background-color: white;
				flex-direction: column;
				.goods {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-left: 120rpx;
					margin-right: 20rpx;
					.s-l {
						font-size: 28rpx;
						color: $textDarkGray-color;
						padding: 10rpx 0;
					}
					.s-r {
						font-size: 24rpx;
						color: $textBlack-color;
					}
				}
			}
			.price {
				display: flex;
				margin: 20rpx;
				justify-content: flex-end;
				.count {
					font-size: 24rpx;
					color: $textDarkGray-color;
				}
				.amount {
					font-size: 24rpx;
					color: $textBlack-color;
					font-weight: bold;
				}
			}
			.bottom-c {
				display: flex;
				margin-left: 30rpx;
				border-top: 2rpx solid $spLine-color;
				align-items: center;
				background-color: white;
				justify-content: flex-end;
				.btn {
					display: flex;
					align-items: center;
					justify-content: center;
					border: 2rpx solid $spLine-color;
					margin: 20rpx;
					border-radius: 4rpx;
					span {
						font-size: 28rpx;
						color: $textBlack-color;
						margin: 16rpx 24rpx;
					}
				}
			}
		}
	}
}
</style>